/*
 * chat_epoll.h
 *
 *  Created on: 2012-6-26
 *      Author: rendong
 */

#ifndef CHAT_EPOLL_H_
#define CHAT_EPOLL_H_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include <sys/epoll.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <fcntl.h>
#include <unistd.h>

#include "../core/chat_log.h"
#include "../core/chat_types.h"
#include "../os/chat_file.h"

#define CLOSE_RSET "connrset"
#define CLOSE_BUFF_FULL "bufferfull"
#define CLOSE_NORMAL "normal"
#define CLOSE_EXCEPTION "exception"
#define CLOSE_DUPLOGIN "duplogin"
#define CLOSE_BROKENPIPE "Broken Pipe"
#define CLOSE_WRITEFAIL "Write Fail"
#define CLOSE_HEARTTIMEOUT "Heart Time Out"
#define CLOSE_CONNTIMEOUT "Connect Time Out"


/**
 * 启动socket服务
 */
void chat_epoll_socket_start(chat_server_config_t *config);

/**
 * 服务器端关闭连接
 */
void chat_epoll_close(chat_server_config_t *config, int sockfd, char *msg);

/**
 * 设置非阻塞
 */
void setnonblocking(int sock);

ssize_t chat_send(chat_session_t *session, void *buffer, size_t n, int is_free);

#endif /* CHAT_EPOLL_H_ */
